import {reqCategoryList,reqGetBannerList,reqGetFloorList} from '@/api'
// 储存数据
const state = {
    categoryList:[],
    bannerList:[],
    floorList:[],
};

const actions = {
    // 调用axios请求
    async getCatgroy({commit}){
        const result = await reqCategoryList();
        // 判断是否已经接收到数据?
        if(result.code === 200){
            // 提交mutation
            commit('GET_CATGROY',result.data)
        }
    },
    async getBannerList({commit}){
        const result = await reqGetBannerList();
        if(result.code === 200){
            // 提交mutation
            commit('GET_BANNERLIST',result.data)
        }
    },
    async getFloorList({commit}){
        const result = await reqGetFloorList();
        if(result.code === 200){
            commit('GET_FLOORLIST',result.data)
        }
    }
};

const mutations = {
    // 接收两个参数  一个是state  一个是value 这个value可以自定义就是仓库的数据
    GET_CATGROY(state,categoryList){
      state.categoryList = categoryList
    },
    GET_BANNERLIST(state,bannerList){
      state.bannerList = bannerList
    },
    GET_FLOORLIST(state,floorList){
        state.floorList = floorList
    }
};

const getters = {

}

export default {
    state,
    actions,
    mutations,
    getters
}